import { _decorator, Component, Node, director, TERRAIN_SOUTH_INDEX } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('UIManager')
export class UIManager extends Component {

    @property(Node)
    uiLevelFailure: Node;

    @property(Node)
    uiLevelSuccess: Node;

    @property(Node)
    uiLevelCompleted: Node;

    start() {
        // 打开关卡失败的监听
        director.getScene().on('level_failed', this.onEvent_LevelFailed, this);
        // 打开关卡成功的监听
        director.getScene().on('level_succeed', this.onEvent_LevelSucceed, this);
        // 打开关卡全部完成的监听
        director.getScene().on('level_completed', this.onEvent_LevelCompleted, this);
    }

    update(deltaTime: number) {
        
    }

    onBtnRePlay() {
        director.loadScene(director.getScene().name);
    }

    onBtnMainMenu() {
        director.loadScene('MainMenu');
    }

    onBtnNext() {
        // 关卡切换
        let currentScene = director.getScene().name;
        if(currentScene == 'level-001') {
            director.loadScene('level-002');
        }
        if(currentScene == 'level-002') {
            director.loadScene('level-003');
        }
    }

    onEvent_LevelFailed() {
        this.uiLevelFailure.active = true;
    }

    onEvent_LevelSucceed() {
        this.uiLevelSuccess.active = true;
    }

    onEvent_LevelCompleted() {
        this.uiLevelCompleted.active = true;
    }

}


